package com.itlaobing.demo.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @Classname OutlineServlet
 * @Description TODO()
 * @Date 2020/11/13 0013 15:53
 * @Author by Administrator
 * @Version v1.0
 */
@WebServlet("/outline")
public class OutlineServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        ServletContext context = getServletContext();
        Map<String, HttpSession> map = (Map<String, HttpSession>) context.getAttribute("onlineUsers");
        HttpSession session = map.get(id);
        session.removeAttribute("user"); // HttpSessionAttributeListener
        session.setMaxInactiveInterval(1);// HttpSessionListener
        resp.sendRedirect("online");
    }
}
